<%--***************************************
*
*网银在线
* 
***************************************--%>
<%@ page import="
	java.math.BigDecimal,
	com.probiz.estore.Constants,
	com.probiz.estore.system.util.TranslateService,
	com.probiz.estore.order.model.OnlinePaymentResponse,
	com.probiz.estore.common.model.system.PaymentGateway,
	com.probiz.estore.system.service.PaymentGatewayManager,
	com.probiz.estore.common.service.OrderService,
	org.springframework.web.context.support.WebApplicationContextUtils,
	org.springframework.web.context.WebApplicationContext"
	pageEncoding="UTF-8"%>
	
<%
	response.setCharacterEncoding("UTF-8");
	WebApplicationContext webAppContext=WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());
	PaymentGatewayManager paymentGatewayManager=(PaymentGatewayManager)webAppContext.getBean("paymentGatewayManager");
	PaymentGateway paymentGateway=paymentGatewayManager.getByPaymentGatewayCode("china_bank");
	
	String key = paymentGateway.getConfigData().get("key").toString().trim();						

	//获取参数
	String v_oid = request.getParameter("v_oid");			// 订单号
	String orderNo = v_oid;
	String v_pmode = request.getParameter("v_pmode");		// 支付方式中文说明，如"中行长城信用卡"
   	String v_pstatus = request.getParameter("v_pstatus");	// 支付结果，20支付完成；30支付失败；
   	String v_pstring = request.getParameter("v_pstring");	// 对支付结果的说明，成功时（v_pstatus=20）为"支付成功"，支付失败时（v_pstatus=30）为"支付失败"
	String amount = request.getParameter("v_amount");		// 订单实际支付金额
 	String v_moneytype = request.getParameter("v_moneytype");	// 币种
	String v_md5str = request.getParameter("v_md5str");		// MD5校验码
	String remark1 = request.getParameter("remark1");		// 备注1
	String remark2 = request.getParameter("remark2");		// 备注2
	
	
	String originalText = v_oid + v_pstatus + amount + v_moneytype + key; 	//拼凑加密串
	String v_md5 = TranslateService.md5Translate(originalText).toUpperCase();
	Short flag = Constants.PAYMENT_HISTORY_FLAG_FAILURE;
	if (v_md5str.equals(v_md5)){
	   if ("30".equals(v_pstatus)){
			out.print("支付失败");
		}else if ("20".equals(v_pstatus)){
		   flag = Constants.PAYMENT_HISTORY_FLAG_SUCCESS;
		}else{
		    out.print("校验码未通过，不是银行传递回来的参数");
		}
	}
	
	OnlinePaymentResponse onlinePaymentResponse = new OnlinePaymentResponse();
	onlinePaymentResponse.setFlowNo(v_oid); //必填. 如果支付网关没有流水号，则使用原始的orderNo，即未decode前的
	onlinePaymentResponse.setOrderNo(orderNo); //必填
	onlinePaymentResponse.setFlag(flag);  //必填
	onlinePaymentResponse.setAmount(new BigDecimal(amount)); //必填
	onlinePaymentResponse.setPaymentGateway(paymentGateway); //必填
	OrderService orderService = (OrderService) webAppContext.getBean("orderService");
	request.setAttribute("onlinePaymentResponse",onlinePaymentResponse);
	orderService.doHandleOnlinePaymentResponse(onlinePaymentResponse,request);
%>

<%@include file="./include/finishPayResult.jspf"%>
